<?php

namespace app\db\index;

class D_setting
{
    /**
     * 所有数据
     * @param string $paramObj
     */
    public function getSetting($paramObj=""){
        $dataObj=paramsObj();
        $dataObj->request=paramsObj();
        $dataObj->data=paramsObj();
        $dataObj->data->use_trans=false;
        $dataObj->result=array();

        $final_arr=logInit();
        if($final_arr["error_no"]==0){
            $mixed=parseToArr($paramObj,"mixed",0);
            $params=parseToArr($paramObj,"params",array());
            $messages=parseToArr($paramObj,"messages",array());
            $rules=array(
                'pid' => '',
                'field' => '',
            );
            $dataDefault=array();
            $dataDefault["field"]="*";
            $dataDefault["pid"]=0;
            $paramsObj=paramsObj();
            $paramsObj->params=$params;
            $paramsObj->mixed=$mixed;
            $paramsObj->rules=$rules;
            $paramsObj->messages=$messages;
            $paramsObj->dataDefault=$dataDefault;
            $checkResult = app("verifyParam")::validatorRequest($paramsObj);
            if($checkResult["error_no"]==0){
                $dataObj->request=$checkResult["result"];
            }else{
                $final_arr=logCallErrorMsg($final_arr,$checkResult);
            }
        }
        if($final_arr["error_no"]==0){
            $condition=array();
            if(is_numeric($dataObj->request->pid) && $dataObj->request->pid >0){
                $condition[]=array(
                    "pid","=",$dataObj->request->pid
                );
            }
            try{
                $result=Db()->name(app("cmsTable")::setting())->field($dataObj->request->field)->where($condition)->select();
                if($result){
                    $temp=array();
                    foreach($result as $val){
                        $temp[$val["pid"]][$val["itemKey"]]=$val["itemValue"];
                    }
                    $result=$temp;
                }
                $final_arr["result"]=$result;
            }catch (\Throwable $e){
                $final_arr=recordLogMsgLevelTwo(app("errorLevel")::E_ERROR,app("errorCode")::SQL_ERROR,lang("sys.error"),$e->getMessage());
            }
        }
        return $final_arr;
    }

    public function __call($name,$arguments)
    {
        return recordLogMsgLevelTwo(app("errorLevel")::E_WARNING,app("errorCode")::UNDEFINED_METHOD,lang("sys.noMethodDefined"),$name,$arguments);
    }
}